<?php

namespace app\admin\controller\tecent;

use app\common\controller\Backend;
use phpQuery;


/**
 * 药品管理
 *
 * @icon fa fa-circle-o
 */
class Cartoon extends Backend
{

    /**
     * Keyword模型对象
     * @var \app\admin\model\tecent\Cartoon
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\tecent\Cartoon;
        $this->view->assign("statusList", $this->model->getStatusList());

    }

    //
    public function remoteAdd()
    {
        $dir = "F:/公众号采集/微信公众号文章批量采集下载助手-V3版本源码-晴澜教育/国漫中/html文件";
        $this->traverse($dir);
    }


    private function traverse($dir)
    {
        $files = scandir($dir);
        foreach ($files as $k => $file) {
            if ($file == '.' || $file == '..') {
                continue;
            }
            $path = $dir . '/' . $file;
            if (is_dir($path)) {
//                traverse($path);
            } else {
//               echo "$k\n";
                if ($k === 2) {
                    $this->getContent($path);
                }
            }
        }
    }

    private function getContent($path)
    {
        $html = file_get_contents($path);
//        echo $html;exit;
        require_once(APP_PATH . '/phpQuery/phpQuery.php');

        $doc = phpQuery::newDocumentHTML($html, 'utf-8');
        //标题
        $source_title = trim($doc->find('h1#activity-name')->text());

        $imgsObject = $doc->find('.rich_pages');

        // 图片
        foreach ($imgsObject as $node) {
            $source_imgs[] = $node->getAttribute("src");
        }

        // 来源作者
        $source_author = trim($doc->find('#js_name')->text());

        // 来源添加时间
        $source_addtime = trim($doc->find('em#publish_time')->text());

        // 来源地址
          $source_link = trim($doc->find("meta[property='og:url']"));
        $newId = $this->model->insertGetId([
            'title' => '',
            'source_title'=>$source_title,
            'createtime' => time(),
            'updatetime' => time(),
            'weigh' => 99,
            'status' => 0,
        ]);
      print_r($newId);
      //  ->getAttribute("content")
       // $source_addr = trim($doc->find(":meta"));



    }


    /**
     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
     */


}
